<template>
  <div class="demo">
    <h2 >学校名：{{name}}</h2>
    <h2>学校地址：{{address}}</h2>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
name:'School',
data(){
    return {    
        name:'尚硅谷',
        address:'北京'
    }
},
mounted(){
/*   this.$bus.$on('hello',(data)=>{
    console.log('我是School组件，收到了数据',data);
  }) */
  this.pubId=pubsub.subscribe('hello',function(magName,data){
      console.log("有人发布了hello消息，回调被执行了",magName,data);
      // console.log(this);//undifined
  })
},
beforeDestroy(){
  // this.$bus.$off('hello')
  pubsub.unsubscribe(this.pubId)
}
}
</script>

<style scoped>
.demo{
    background-color: skyblue;
}
</style>